//
//  ReceiveTaskController.m
//  Safflower
//
//  Created by 袁亮 on 2016/12/23.
//  Copyright © 2016年 Migic_Z. All rights reserved.
//

#import "ReceiveTaskController.h"
#import "ReceiveTaskView.h"
#import "TaskDataCenter.h"

@interface ReceiveTaskController ()<ReceiveTaskViewDelegate>

@property (nonatomic, strong) ReceiveTaskView *receiveTaskView;
@property (nonatomic, strong) TaskDataCenter *dataCenter;

@end

@implementation ReceiveTaskController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.baseTitle = self.taskModel.name;
    self.rightBtnTitle = @"返回";
    
    
    _dataCenter = [TaskDataCenter new];
    
    [self makeReceiveTaskView];
    
    [self loadReceiveData:self.taskModel];
}

- (void)makeReceiveTaskView
{
    _receiveTaskView = [ReceiveTaskView new];
    _receiveTaskView.delegate = self;
    [self.baseView addSubview:_receiveTaskView];
    [_receiveTaskView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.bottom.mas_equalTo(-20);
        make.left.mas_equalTo(40);
        make.right.mas_equalTo(-40);
    }];
}

- (void)loadReceiveData:(TaskModel *)model
{
    [_receiveTaskView loadReceiveTask:model];
}

- (void)clickRefuseTask:(TaskModel *)task
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)clickReceiveTask:(TaskModel *)task
{
    [YJProgressHud showLoadingHud:@"努力接受中..."];
    [_dataCenter receiveTask:task complation:^(NSString *error) {
        if (error == nil) {
            [YJProgressHud showSuccessHud:@"接受成功"];
            [self.navigationController popViewControllerAnimated:YES];
            if ([self.delegate respondsToSelector:@selector(receiveSuccessReloadData)]) {
                [self.delegate receiveSuccessReloadData];
            }
        }else{
            [YJProgressHud showErrorHud:error];
        }
    }];
}


- (void)clickRightButton
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
